using Microsoft.Xna.Framework;

namespace WPCoco.Tasks
{
    public class AnchorBy : TargetedTask<IAffine>
    {
        public AnchorBy(Vector2 anchor, float duration)
            : base(duration)
        {
            this.anchor = anchor;
        }

        Vector2 anchor;
        Vector2 delta;
        Vector2 start;

        public override void InitializeWithTarget(IAffine target)
        {
            start = target.Anchor;
            delta = anchor / Duration;
        }

        public override void UpdateWithTarget(IAffine target, float time)
        {
            target.Anchor = start + delta * time;
        }

        public override Task Clone()
        {
            return new AnchorBy(anchor, Duration);
        }

        public override Task Reverse()
        {
            return new AnchorBy(-anchor, Duration);
        }
    }
}
